package com.example.mycontinuation

import kotlinx.coroutines.*
import org.junit.Test

import org.junit.Assert.*
import java.text.SimpleDateFormat
import java.util.*
import kotlin.concurrent.thread
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

/**
 * Example local unit test, which will execute on the development machine (host).
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
class ExampleUnitTest {
    @Test
    fun addition_isCorrect() {
        assertEquals(4, 2 + 2)
//        val job = GlobalScope.launch(Dispatchers.IO+CoroutineName("MyGlobalScope")) {
//            log("Hello")
//            delay(1000)
//            log("World")
//            thread {  }
//        }
        runBlocking {
            delay(1000)
        }

        GlobalScope.launch {


        }

        CoroutineScope(EmptyCoroutineContext).launch {
            val job = launch{ }
            job.cancel()
            val deferred = async { }
            deferred.await()
            withContext(Dispatchers.IO){ }
        }


//        job[CoroutineName]

        log("out")
        log("out")
        Thread.sleep(2000)
        log("out")
        log("out")

//
//        val minusKey = job.minusKey(Job)
//        job.cancel()
//        var d= 0
//        log(d)
//
//        val s = ++d
//        log(s)
//        log(d)


        Thread.sleep(100000)
    }

//    suspend fun hi(): Int {
//        delay(10000)
//        return 5
//    }
//    suspend fun hi2(int: Int): Int {
//        delay(1000)
//        return 2+int
//    }
//    suspend fun hi3(int: Int): Int {
//        delay(1000)
//        return 3+int
//    }


    suspend fun nosuspend():String{
        delay(1000)
        Thread.sleep(1000)
     return "nosuspend"
    }

    private val dateFormat = SimpleDateFormat("HH:mm:ss:SSS")
    val now = { dateFormat.format(Date(System.currentTimeMillis())) }
    fun log(msg: Any?){
        println("${now()} [${Thread.currentThread().name}] $msg")
    }




}